<html>
<head>
	<meta charset="UTF-8">
	<METAHTTP-EQUIV="Pragma"CONTENT="no-cache">
	<METAHTTP-EQUIV="Cache-Control"CONTENT="no-cache">
	<METAHTTP-EQUIV="Expires"CONTENT="0">
	<link rel="stylesheet" href="css/bootstrap.css"> 
	<script src="js/jquery.js"></script>
	<script src="js/angular.js"></script>
	<script type="text/javascript" src="js/bootstrap.js"></script>
</head>
<body>
	<div><a href="index.html">退出</a>&nbsp;&nbsp;<a href="sendMessage.html">新增</a>
		<div style="text-align: right;"><iframe src="header.html" style="position: absolute;top:0px;right: 0px;border: none;width:150px;height:20px;background:transparent;"></iframe></div>
	</div>
	<div class="panel panel-default"  ng-app="myApp" ng-controller="siteCtrl">
		<div class="panel-heading">
	        <h1 style="text-align: center;">
	        	{{name}}
	        </h1>
	    </div>
	    <div class="panel-body"> 
			<input type="date" ng-model="date"/>
			<input type="button" class="btn btn-primary" ng-click="submit()" value="查询">
			<table class="table table-bordered table-hover" style="table-layout: fixed;">
			  <caption>发送记录</caption>
			  <thead>
			  	<colgroup>
				    <col width='10%'></col>
				    <col></col>
				    <col></col>
				    <col></col>
				    <col></col>
				    <col width='20%'></col>
				    <col></col>
				    <col></col>
				    <col></col>
				  </colgroup>
			    <tr>
			      <th>模板ID</th>
			      <th>预计发送时间</th>
			      <th>实际发送时间</th>
			      <th>跳转URL</th>
			      <th>字体颜色</th>
			      <th>发送内容</th>
			      <th>状态</th>
			      <th>备注</th>
			      <th>操作</th>
			    </tr>
			  </thead>
			  <tbody>
			     <tr class="{{outerIndex%2==0?'success':'danger'}}" ng-repeat="x in datas" ng-init="outerIndex = $index">
			    	
				    <td style="overflow: hidden; text-overflow:ellipsis;white-space: nowrap" title="{{ x.templateId }}">{{ x.templateId}}</td>
				    <td >{{ x.setSendTime }}</td>
				    <td >{{ x.sendTime }}</td>
				    <td style="overflow: hidden; text-overflow:ellipsis;white-space: nowrap" title="{{ x.clickurl }}">{{ x.clickurl }}</td>
				    <td >{{ x.topcolor }}</td>
				    <td style="overflow: hidden; text-overflow:ellipsis;white-space: nowrap" title="{{ x.data }}">{{ x.data }}</td>
				    <td >{{ x.isSend==1?'已发送':'未发送' }}</td>
				    <td >{{ x.note }}</td>
				    <td ><a href="sendMessage.html?id={{x.id}}&createDate={{date.format('yyyyMMdd')}}">编辑</a>&nbsp;&nbsp;<a href="" ng-click="deleteRecord(x.id,date.format('yyyyMMdd'),x.isSend)">删除</a></td>
				  </tr>
			  </tbody>
			</table>
		</div>
</div>
	
	
	<script type="text/javascript">
	
	Date.prototype.format = function(format)
	{
	 var o = {
	 "M+" : this.getMonth()+1, //month
	 "d+" : this.getDate(),    //day
	 "h+" : this.getHours(),   //hour
	 "m+" : this.getMinutes(), //minute
	 "s+" : this.getSeconds(), //second
	 "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
	 "S" : this.getMilliseconds() //millisecond
	 }
	 if(/(y+)/.test(format)) format=format.replace(RegExp.$1,
	 (this.getFullYear()+"").substr(4 - RegExp.$1.length));
	 for(var k in o)if(new RegExp("("+ k +")").test(format))
	 format = format.replace(RegExp.$1,
	 RegExp.$1.length==1 ? o[k] :
	 ("00"+ o[k]).substr((""+ o[k]).length));
	 return format;
	}
	
	var app = angular.module('myApp', []);
    
	app.controller('siteCtrl', function($scope, $http) {
		/* $http.get('/get?date=2017-08-11').then(function successCallback(response) {
				console.log(response)
	            $scope.names = response.data.sites;
	        }, function errorCallback(response) {
	            // 请求失败执行代码
	    }); */
	    
	    $scope.date=new Date();
	    
	  	$scope.submit=function(){
	  		if($scope.date==undefined){
	  			alert("请选择日期");
	  			return;
	  		}
	  		 $http.get('/get?date='+$scope.date.format('yyyyMMdd')).then(function successCallback(response) {
					console.log(response)
		            $scope.datas = response.data;
		        }, function errorCallback(response) {
		            // 请求失败执行代码
		    });
	  	}
	  	
	  	$scope.deleteRecord=function(templateId,createDate,isSend){
	  		if(isSend==1){
	  			alert("已发送的消息不能删除!")
	  		}
	  		$http.get('/delete?createDate='+createDate+"&id="+templateId).then(function successCallback(response) {
	  			$scope.submit();
	        }, function errorCallback(response) {
	            // 请求失败执行代码
	            console.log(response)
	    	});
	  	}
	  	
	  	$http.get('/getApp').then(function successCallback(response) {
  			console.log(response);
  			$scope.name=response.data.name;
        }, function errorCallback(response) {
            // 请求失败执行代码
            console.log(response)
    	});
	  	
	  	$scope.submit();
	});
	</script>
</body>
</html>